using System.Data;
using MySqlConnector;

namespace Front._1124;

public partial class BookMain : Form
{
    public BookMain()
    {
        InitializeComponent();
    }


    private void BookMain_Load(object sender, EventArgs e)
    {
        GetAllBooks();
        
        
        GetAllCategories();
    }

    private void GetAllCategories()
    {
        
    }

    private void GetAllBooks()
    {
        using var connection = new MySqlConnection("server=localhost;port=3306;database=book;user=root;password=root;charset=utf8mb4;AllowPublicKeyRetrieval=True;");
        connection.Open();
       
        String sql = "select distinct book_category from book_info;";
        
        MySqlDataAdapter mysqlDataAdapter = new MySqlDataAdapter(sql, connection);
        
        DataSet dataSet = new DataSet();
        mysqlDataAdapter.Fill(dataSet, "book_info");
        //this.dataGridView1.DataSource = dataSet.Tables["book_category"];
        DataTable dataTable = dataSet.Tables["book_info"];
        DataRow row = dataTable.NewRow();
        row[0] = "全部";
        dataTable.Rows.InsertAt(row, 0);
        
        comboBox1.DataSource = dataTable;
        comboBox1.DisplayMember = dataTable.Columns[0].ColumnName;

    }


    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        
    }
}